exports.count = function (app, db) {
  // 纪录用户在线的中间件
  app.use(function (req, res, next) {
    var ua = req.headers['user-agent'];
    db.zadd('online', Date.now(), ua, next);
  });
  // 通过zrevrangebyscore来查询上一分钟在线用户
  app.use(function (req, res, next) {
    var min = 60 * 1000;
    var ago = Date.now() - min;
    db.zrevrangebyscore('online', '+inf', ago, function (err, users) {
      if (err) return next(err);
      req.online = users;
      next();
    });
  });
}